package com.bamanker.cloudconsumer.controller;

import com.bamanker.cloudapi.domain.toEmail;
import com.bamanker.cloudconsumer.feign.EmailClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author bamanker
 */
@Controller
@RequiredArgsConstructor
public class EmailConsumerController {

    private final EmailClient emailClient;

    /*页面跳转 部分*/
    @RequestMapping(value = "/listToEmails", method = RequestMethod.GET)
    public ModelAndView listToEmail() {
        ModelAndView mv = new ModelAndView();
//        if (StpUtil.isLogin()) {
//            mv.addObject("loginId", StpUtil.getLoginId());
        mv.setViewName("listToEmails");
        return mv;
//        }
//        return new ModelAndView("login");
    }

    @RequestMapping(value = "/editToEmails", method = RequestMethod.GET)
    public ModelAndView editToEmail() {
        return new ModelAndView("editToEmails");
    }

    @GetMapping("/toEmails")
    @ResponseBody
    public Object list(@RequestParam(value = "start",defaultValue = "1") int start,
                                @RequestParam(value = "size",defaultValue = "5") int size) {
        return emailClient.list(start,size);
    }

    @GetMapping("/toEmails/{id}")
    @ResponseBody
    public Object get(@PathVariable("id") int id) {
       return emailClient.get(id);
    }

    @PostMapping("/toEmails")
    @ResponseBody
    public Object add(@RequestBody toEmail t) {
        return emailClient.add(t);
    }

    @DeleteMapping("/toEmails/{id}")
    @ResponseBody
//    @SaCheckPermission(value = "user.delete")
    public Object delete(@PathVariable("id") long id) {

        return emailClient.delete(id);
    }

    @PutMapping("/toEmails/{id}")
    @ResponseBody
    public Object update(@RequestBody toEmail t) {
        return emailClient.update(t);
    }


}
